using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
using System.Linq;

[CustomEditor(typeof(Entity), true)]
[CanEditMultipleObjects]
public class EntityEditor : Editor {
    
    SerializedProperty property;

    public override void OnInspectorGUI() {
        //DrawDefaultInspector();
        Entity entity = target as Entity;
        
        property = serializedObject.GetIterator();
        property.Next(true);
        property.NextVisible(false);//跳过Script属性
        
        EditorGUILayout.Space();
        EditorGUILayout.LabelField("——————实体属性——————");
        EditorGUILayout.Space();

        string type = Enum.GetName(typeof(EntityType), entity.type);
        
        EditorGUI.BeginChangeCheck();

        while(property.NextVisible(false)){
            List<string> types = new List<string>(property.tooltip.Split('|'));
            bool enable = true;

            if(types.Exists(t => t.Contains("Disable"))){
                enable = false;
            }
            
            if(!types.Exists(t => t.Contains(type))){
                GUI.enabled = enable;
                EditorGUILayout.PropertyField(property);
                GUI.enabled = true;
            }
            
            
            if(property.name == "tags"){
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("——————其他属性——————");
                EditorGUILayout.Space();
            }

        }

        if(EditorGUI.EndChangeCheck()){
            EditorUtility.SetDirty(entity);
        }
        
        serializedObject.ApplyModifiedPropertiesWithoutUndo();
    }
}
//*/